<?php

var_dump($argv);
var_dump($argc);
$dd=null;
if(isset($argv[1])){

	ts( $argv[1]);
}else{

ts( "need  a file name");
exit(-1);
}
function ts($str){

	echo( $str."\n\n");
}

$jadxExe="G:\\apk\\tool\\jadax\\bin\\jadx";
$smaliExe="F:\\wuai\\wuai\\Tools\\AndroidTools\\AndroidKiller_v1.3.1\\bin\\dex2jar\\d2j-dex2smali.bat";

$fullName=$argv[1];
$dirName=realpath("./");
$project=$dirName."\\"."project";
ts( $project);

$singleName=basename($fullName);

ts( "singleName:".$singleName);

$projectDir=$project."\\".strstr($singleName,".",true);

$smaliDir=$projectDir."\\"."smali";

$sourceJavaDir=$projectDir."\\"."sourceJava";

function  newDir($dir){

	if(!is_dir($dir)){

		if(mkdir($dir)){

		ts( "mkdir $dir  success");
		}else{

		ts( "mkdir $dir failed");
		}
	}else{

	ts( "already $dir exits");
	}
}
if(strpos($singleName,".apk") || strpos($singleName,".dex") || strpos($singleName,".class") || strpos($singleName,"jar")){
	

	newDir($projectDir);
	//newDir($smaliDir);
	newDir($sourceJavaDir);
	

	if(dirIsEmpty($sourceJavaDir) == 0){
	$javasql =$jadxExe." -r  -d ".$sourceJavaDir."  ".$fullName;
	ts( "\n $sql \n");
	
	$result=system($javasql);  //生成java文件 用jadax
	ts( $result);
	}

	if(dirIsEmpty($smaliDir) == -99){
	$smalisql = $smaliExe." -o ".$smaliDir." ".$fullName;
	ts("$smalisql");
	$result=system($smalisql);
	ts($result);
	}

	

}else{

	ts( "---sorry  this type file not suit ---");
}
function dirIsEmpty($dir){

		if(is_dir($dir)){


				$handle=opendir($dir);
				$count=0;

					while(($read=readdir($handle))){

						if($read == "." || $read == ".."){

							continue;
						}
						else{

							$count++;
							
						}
					}

					ts($dir." have subfile count:".$count);
				return $count++;

		}else{

			return -99;
		}

}














?>